package main

import (
	"fmt"
)

/**
GO 面向对象
结构体方法的使用
（类似与class某个类的方法）
方法的访问控制也是通过首字母的大小写控制(大写为public)
 */

type rect struct {
	width, height int
}

func (r *rect) area() int {
	return r.width * r.height
}

func (r rect) perim() int {
	return 2*r.width + 2*r.height
}

//init 初始化函数
func (r *rect) init(width, height int){
	r.height = height
	r.width = width
}

func (r rect) GetHeight() int{
	return r.height
}

func (r *rect) SetHeight(height int){
	r.height = height
}

func main() {
	r := rect{width: 10, height: 5}
	fmt.Println("area: ", r.area())
	fmt.Println("perim:", r.perim())

	rp := &r
	fmt.Println("area: ", rp.area())
	fmt.Println("perim:", rp.perim())

	var r1 rect
	r1.init(20,30)
	height := r1.GetHeight()
	fmt.Println("height:",height)
	r1.SetHeight(15)

	fmt.Println("height:", r1.GetHeight())
	fmt.Println("area: ", r1.area())
	fmt.Println("perim:", r1.perim())

}
